﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
public partial class Admin_addClassAttribute : System.Web.UI.Page
{
    ClassAttributeBll cAttrBll = new ClassAttributeBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            if (Request.QueryString["action"]!=null)
            {               
                string action = Request.QueryString["action"].Trim();                
                switch (action)
                {
                    case "load":                        
                        this.pClassID_hid.Value = Request.QueryString["pClassID"];
                        if (cAttrBll.GetModelByClassID(Convert.ToInt32(Request.QueryString["pClassID"])).pClassID != 0)
                        {
                            Classload();
                        }
                        break;
                    case "insert":
                        Insert();
                        break;
                    default:
                        break;
                }
            }
        }
    }
    public void Classload() 
    {
        ClassAttribute cAttr = cAttrBll.GetModelByClassID(Convert.ToInt32(Request.QueryString["pClassID"]));
        this.txt_cDescription.Value = cAttr.classDescription;
        this.cTitle.Value = cAttr.cTitle;
        this.cKey.Value = cAttr.cKey;
        this.cDescription.Value = cAttr.cDescription;
        this.FCKeditor1.Value = cAttr.classRelationMap;
        this.classAttributeID.Value = cAttr.classAttributeID.ToString();
    }
    public void Insert() 
    {
        ClassAttribute cAttr = new ClassAttribute();
        cAttr.pClassID = Convert.ToInt32(Request.Form["pClassID_hid"]);
        cAttr.classDescription = Request.Form["txt_cDescription"].ToString();
        cAttr.cTitle = Request.Form["cTitle"].ToString();
        cAttr.cKey = Request.Form["cKey"].ToString();
        cAttr.cDescription = Request.Form["cDescription"].ToString();
        cAttr.classRelationMap =Server.HtmlDecode( Request.Form["FCKeditor1"].ToString());
        if (Request.Form["classAttributeID"] == "")
        {
            if (cAttrBll.Insert(cAttr))
            {
                Response.Write("1");
            }
            else
            {
                Response.Write("添加失败！");
            }            
        }
        else 
        {
            cAttr.classAttributeID = Convert.ToInt32(Request.Form["classAttributeID"]);
            if (cAttrBll.Update(cAttr))
            {
                Response.Write("1");
            }
            else 
            {
                Response.Write("修改失败！");
            }
        }
        Response.End();
        
    }

}
